package xhwl.hmo.mall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import xhwl.hmo.mall.R;
import xhwl.hmo.mall.http.bean.resp.NewProductResp;
import xhwl.hmo.mall.utils.GlideRoundTransform;
import xhwl.pulltorefresh.adapter.BaseAdapter;
import xhwl.pulltorefresh.adapter.ViewHolder;

/**
 * Created by admin on 2017-10-25.
 */

public class HorizontalRecycleViewAdapter extends BaseAdapter<NewProductResp> {
    OnItemClickLitener onItemClickLitener;
    public HorizontalRecycleViewAdapter(Context context, List<NewProductResp> datas) {
        super(context, R.layout.item_newproduct, datas);
    }

    @Override
    public void convert(ViewHolder holder, NewProductResp newProductResp) {
        holder.setText(R.id.tv_new_product_name, newProductResp.GOODS_NAME);
        holder.setText(R.id.tv_new_product_price,"¥ "+newProductResp.PROMOTION_PRICE+"/年");
        ImageView img_new_product=holder.getView(R.id.img_new_product);
//        Glide.with(context).load(newProductResp.DISPLAY_PIC).into(img_new_product);
        Glide.with(context)
                .load(newProductResp.DISPLAY_PIC)
                .transform(new GlideRoundTransform(context)).placeholder(R.drawable.load).error(R.drawable.loadfail)
                .into(img_new_product);
        // 如果设置了回调，则设置点击事件
        final int pos = holder.getLayoutPosition();
        if (onItemClickLitener != null) {
            holder.setOnclickListener(R.id.linear_new_product, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickLitener.onItemClick(pos);
                }
            });
        }

    }
    public interface OnItemClickLitener {
        void onItemClick(int position);
    }

    public void setOnItemClickLitener(OnItemClickLitener onItemClickLitener) {
        this.onItemClickLitener = onItemClickLitener;
    }
}
